var path = require('path');
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin"); //将组件中的样式乖乖提取出来

var HtmlWebpackPlugin = require('html-webpack-plugin'); //html模板插入代码
//webpck插件


var plugins = [
  //提公用js到common.js文件中


  new webpack.optimize.CommonsChunkPlugin('common.js'),
  new HtmlWebpackPlugin({
    title: "avalon webpack gulp spa ",
    template: "tpl.html",
    filename: "index.html",
    hash: true
  }),
  //将样式统一发布到style.css中


  new ExtractTextPlugin("style.css", {
    allChunks: true,
    disable: false
  }),

];
var entry = ['./src/main.js'],
  buildPath = "/dist/";
//编译输出路径


module.exports = {
  debug: true,
  entry: entry,
  output: {
    path: __dirname + buildPath,
    filename: 'build.js',
    publicPath: '',
    chunkFilename: "[name].chunk.[chunkhash:8].js" //给require.ensure用

  },
  module: {
    loaders: [{
      test: /\.css$/,
      loader: ExtractTextPlugin.extract(
        "style-loader", "css-loader?sourceMap!cssnext-loader")
    }, {
      test: /\.(jpg|png|gif)$/,
      loader: "file-loader?name=images/[name].[hash].[ext]"
    }, {
      test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
      loader: "url-loader?limit=10000&minetype=application/font-woff"
    },
     {
      test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
      loader: "file-loader"
    },
    {
      test: /\.json$/,
      loader: 'json'
    }]
    // ,
    // preLoaders: [{
    //   test: /\.js$/,
    //   loader: "require-css-preloader"
    // }]
  },

  resolve: {
    // require时省略的扩展名，如：require('module') 不需要module.js
    extension: ['', '.js', '.css']
    ,
    //别名

    alias: {
      avalon: path.join(__dirname, 'src/assets/vendor/avalon/dist/avalon.mobile.shim.js')
      //主要用于移动端，所以采用avalon.mobile.shim(不带加载器的移动版本)
    }
  }
  ,
  plugins: plugins,
  //  devtool: '#source-map'
};
